package com.fstec.ks.master.netty.receiver;

import org.springframework.beans.factory.annotation.Autowired;

import com.fstec.ks.master.MasterEngine;
import com.fstec.ks.master.netty.DefaultComputer;
import com.fstec.ks.master.netty.ExamExceptionMessage;
import com.fstec.ks.master.netty.ResponseMessageType;
import com.sinotn.ks.definition.Computer;
import com.sinotn.ks.definition.Message;
import com.sinotn.ks.definition.MessageReceiver;
import com.sinotn.ks.netty.message.SimpleMessage;

/**
 * 已授权绑定的考试服务器登录监控服务
 * @Title ServerLoginReceiver.java
 * @Package com.fstec.ks.master.netty.receiver
 * @Description 
 * Copyright: Copyright (c) 2023
 * Company:广东峰上科技有限公司
 * 
 * @author <a href="mailto:xieqj@fstec.com">谢启进</a>
 * @date 2023年10月12日 下午4:04:49
 * @version V1.0
 */
public class ServerLoginReceiver implements MessageReceiver {
	@Autowired
	private MasterEngine masterEngine;
	private int type=102;
	
	@Override
	public int getType() {
		return this.type;
	}

	public void setType(int type) {
		this.type = type;
	}

	@Override
	public void process(Computer computer, Message msg) {
		String text=msg.getText();
		if(text==null||text.length()==0){
			throw new ExamExceptionMessage(ResponseMessageType.ERR_BIZ,"客户端参数不能为空");
		}
		DefaultComputer defaultComputer=(DefaultComputer)computer;
		defaultComputer.setVendor(Computer.VENDOR_MANAGE);
		defaultComputer.setRegKey(text);
		masterEngine.onComputerConnect(defaultComputer);
		SimpleMessage sm=new SimpleMessage(ResponseMessageType.SUCCESS, msg.getToken());
		sm.setText(text);
		computer.sendMessage(sm);
	}
}
